package com.chijun.mform.show;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.ccj.u.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShowData {

    List<ModeShowFullForm> showFullFormList;
    Map<Long,Map<String,String>> fieldDataMap;    //要展示的字段 <表单id<字段名，字段内容>>

    public static ShowData parseTheData(String resultData){
        ShowData showData = new ShowData();
        JSONObject jsonObject = JSONObject.parseObject(resultData);

        showData.showFullFormList = new ArrayList<>();
        if (jsonObject.containsKey("formFull")) {
            String full = jsonObject.getString("formFull");
            List<ModeShowFullForm> modeShowFullForms = JSON.parseArray(full, ModeShowFullForm.class);
            if (modeShowFullForms != null) showData.showFullFormList = modeShowFullForms;
        }

        showData.fieldDataMap = new HashMap<>();
        if (jsonObject.containsKey("fullShowField")) {
            String fullShowField = jsonObject.getString("fullShowField");
            Map<Long, Map<String, String>> convertedMap = JSON.parseObject(fullShowField, new TypeReference<Map<Long, Map<String, String>>>() {});
            if (convertedMap != null) {
                showData.fieldDataMap = convertedMap;
                for (Long l : convertedMap.keySet()) {
                    LogUtils.d(l + "---" + convertedMap.get(l).toString());
                }
            }
        }
        return showData;
    }



}
